package com.jh.config;

import com.jh.util.YmlUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

@Configuration
public class UploadConfig implements WebMvcConfigurer {

//    @Value("${file.icon.path}")
//    private String uploadUrl;


    /***告诉spring 静态文件访问地址
     * 功能说明：配置静态访问资源
     *          文件访问地址配置
     *          参考地址 https://blog.csdn.net/taiguolaotu/article/details/105405174
     * @param registry registry
     * @return void
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String iconAbsolutePath = YmlUtils.getCommonYml("file.icon.path").toString();
        // D://temp//icon
        //指定盘符 回显需要这么写(windows环境)
        registry.addResourceHandler("/icon/**").addResourceLocations("file:D:/temp/icon/");  //行得通
//        registry.addResourceHandler("/icon/**").addResourceLocations("file:D://temp//icon//");    //行的通


        //====================================================================================================
        //http://192.168.30.40:8802/manage/Icon/uploadFiles 上传文件路径 上传到 D:\temp\menhu\2021\8 文件夹下
        //访问时,这么访问 http://localhost:8802/menhu/2021/8/01d9c4363a0b4c838e315e790cbc6896.jpg  因此上传图片后,需要将该图片上传所在的年 月 文件夹名称保存到数据库中,下次访问时,在进行返回。
//        registry.addResourceHandler("/menhu/**").addResourceLocations("file:D://temp//menhu//");    //行的通

        //====================================================================================================
        //http://192.168.30.40:8802/manage/Icon/uploadFiles 上传文件路径 上传到 D:\temp\menhu\2021\8 文件夹下
        //访问时,这么访问 http://localhost:8802/menhu/01d9c4363a0b4c838e315e790cbc6896.jpg   这是因为已经将年月的文件夹加在了后面的locations中
        registry.addResourceHandler("/menhu/**").addResourceLocations("file:D://temp//menhu//2021//8//");    //行的通


//        registry.addResourceHandler("/icon/**").addResourceLocations("file:" + iconAbsolutePath); //行不通
//        registry.addResourceHandler("/icon/**").addResourceLocations("file:+ iconAbsolutePath"); //行不通


//=====================================================================================================
//        linux环境下
        /***告诉spring 静态文件访问地址
         * 功能说明：配置静态访问资源
         *          文件访问地址配置
         * @param registry registry
         * @return void
         */
//        @Override
//        public void addResourceHandlers(ResourceHandlerRegistry registry) {
//            registry.addResourceHandler("/static/upload/**").addResourceLocations("file:" + uploadUrl);
//        }

//     application.yml 配置文件
//        zmj:
//          uploadPhoto: /root/photo/src/main/resources/static/upload
    }

    @Override
    public void addCorsMappings(CorsRegistry corsRegistry) {

    }

    @Override
    public void addViewControllers(ViewControllerRegistry viewControllerRegistry) {

    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry viewResolverRegistry) {

    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> list) {

    }

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> list) {

    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> list) {

    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> list) {

    }

    @Override
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {

    }

    @Override
    public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {

    }

    @Override
    public Validator getValidator() {
        return null;
    }

    @Override
    public MessageCodesResolver getMessageCodesResolver() {
        return null;
    }


    @Override
    public void configurePathMatch(PathMatchConfigurer pathMatchConfigurer) {

    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer contentNegotiationConfigurer) {

    }

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer asyncSupportConfigurer) {

    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer defaultServletHandlerConfigurer) {

    }

    @Override
    public void addFormatters(FormatterRegistry formatterRegistry) {

    }

    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry) {

    }
}
